package com.epoint.mobileoa.personalized.epointcompany.ui.gzrz;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.dom4j.Element;

import android.os.Message;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.datanalysis.XMLHelp;
import com.epoint.mobileoa.db.DBHelp;
import com.epoint.mobileoa.personalized.epointcompany.model.QiandaoInfoModel;
import com.epoint.mobileoa.personalized.epointcompany.model.ShenHeInfoModel;
import com.epoint.mobileoa.tools.WebServiceUtilDAL;

/**
 * @author liyc
 * @time 2012-8-15 上午10:40:56
 * @annotation 
 */
public class GetRizhiShenHeInfoListTask extends Task {

	/**
	 * @param con
	 * @param param
	 */
	public GetRizhiShenHeInfoListTask(SuperView con, Map<String, Object> param) {
		super(con, param);
	}

	@Override
	public void exectue(Message mess) throws Exception {
		String firstDay = getParam().get("firstDay").toString();
		String lastDay = getParam().get("lastDay").toString();
		String CheckUserGuid = getFP().getUserguid();
		String OuGuid = DBHelp.getUserOuguid(getCon(), CheckUserGuid);
		String url = getCon().getString(R.string.epointcompany_rizhi_url);
		String namespace = getCon().getString(R.string.epointcompany_rizhi_namespace);
		String method = "GetCheckMainPageInfo";
		WebServiceUtilDAL webservice = new WebServiceUtilDAL(url,
				method, namespace);
		webservice.addProperty("CheckUserGuid",CheckUserGuid);
		webservice.addProperty("StartDate",firstDay);
		webservice.addProperty("EndDate",lastDay);
		webservice.addProperty("OUGuid",OuGuid);
		String bs = webservice.start();
		System.out.println(bs);
		setMessageToRefreshUI(mess, getCon(), bs);
	}

	public static List<ShenHeInfoModel> XmlAnalysis(String xml){
		List focs = XMLHelp.getRoot(xml).elements();
		List<ShenHeInfoModel> plist = new ArrayList<ShenHeInfoModel>();
		for (int i = 0; i < focs.size(); i++) {
			ShenHeInfoModel mt = new ShenHeInfoModel();
			Element foc = (Element) focs.get(i);
			if (foc.element("RZDate") != null)
				mt.RZDate = foc.elementText("RZDate");
			if (foc.element("CheckStatus") != null)
				mt.CheckStatus = foc.elementText("CheckStatus");
			if (foc.element("CheckUserCount") != null)
				mt.CheckUserCount = foc.elementText("CheckUserCount");
			if (foc.element("UnCheckUserCount") != null)
				mt.UnCheckUserCount = foc.elementText("UnCheckUserCount");
			if (foc.element("UnAddUserCount") != null)
				mt.UnAddUserCount = foc.elementText("UnAddUserCount");
			
			if (foc.element("BuTianUserCount") != null)
				mt.BuTianUserCount = foc.elementText("BuTianUserCount");
			if (foc.element("CheckUserList") != null)
				mt.CheckUserList = foc.elementText("CheckUserList");
			if (foc.element("UnCheckUserList") != null)
				mt.UnCheckUserList = foc.elementText("UnCheckUserList");
			plist.add(mt);
		}
		return plist;
	}
}
